package com.kong.universal;

import lombok.extern.slf4j.Slf4j;
import org.burgeon.commons.react.Result;
import org.burgeon.commons.runtime.ThreadContextHolder;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.apache.commons.lang3.exception.ExceptionUtils;

/**
 * 异常处理
 */
@RestControllerAdvice
@Slf4j
public class ExceptionHandlerAdvisor {

    @ExceptionHandler(Exception.class)
    public Result<String> exceptionHandler(Exception e){
        String stackTrace = ExceptionUtils.getStackTrace(e);
        log.error(stackTrace);
        String error = ExceptionUtils.getMessage(e);
        ThreadContextHolder.setCurrentError(error);
        return Result.data(-4,error,"程序执行错误");
    }

}
